import { Router } from 'express';
import { logger } from '../utils/logger';

// 客户端路由导入
import clientAuthRoutes from './client/auth';
import clientUserRoutes from './client/users';
import clientArtistRoutes from './client/artists';
import clientPerformanceRoutes from './client/performances';
import clientVoteRoutes from './client/votes';
import clientBadgeRoutes from './client/badges';
import clientVenueRoutes from './client/venues';
import clientFloorRoutes from './client/floors';
import clientFunFactRoutes from './client/funFacts';
import clientAIAssistantRoutes from './client/aiAssistants';
import clientDifyAIRoutes from './client/difyAI';
import clientNotificationRoutes from './client/notifications';
import clientNavigationRoutes from './client/navigation';

// 管理后台路由导入
import adminAuthRoutes from './admin/auth';
import adminUserRoutes from './admin/users';
import adminRoleRoutes from './admin/roles';
import adminPermissionRoutes from './admin/permissions';
import adminSystemRoutes from './admin/system';
import adminLogRoutes from './admin/logs';
import adminArtistRoutes from './admin/artists';
import adminPerformanceRoutes from './admin/performances';
import adminVoteRoutes from './admin/votes';
import adminActivityRoutes from '../admin/routes/activities';
import adminContentRoutes from './admin/content';
import adminWorkRoutes from './admin/works';
import adminFloorRoutes from './admin/floors';
import adminVenueRoutes from './admin/venues';

const router = Router();

// 路由配置函数
export function configureRoutes(): Router {
  logger.info('🔧 配置API路由...');

  // 客户端API路由 (Client API)
logger.info('📱 注册客户端API路由: /api/client/*');
router.use('/api/client/auth', clientAuthRoutes);
router.use('/api/client/users', clientUserRoutes);
router.use('/api/client/artists', clientArtistRoutes);
router.use('/api/client/performances', clientPerformanceRoutes);
router.use('/api/client/votes', clientVoteRoutes);
router.use('/api/client/badges', clientBadgeRoutes);
router.use('/api/client/venues', clientVenueRoutes);
router.use('/api/client/floors', clientFloorRoutes);
router.use('/api/client/fun-facts', clientFunFactRoutes);
router.use('/api/client/ai-assistants', clientAIAssistantRoutes);
router.use('/api/client/dify-ai', clientDifyAIRoutes);
router.use('/api/client/notifications', clientNotificationRoutes);
router.use('/api/client/navigation', clientNavigationRoutes);

  // 管理后台API路由 (Admin API)
  logger.info('⚙️ 注册管理后台API路由: /api/admin/*');
  router.use('/api/admin/auth', adminAuthRoutes);
  router.use('/api/admin/users', adminUserRoutes);
  router.use('/api/admin/roles', adminRoleRoutes);
  router.use('/api/admin/permissions', adminPermissionRoutes);
  router.use('/api/admin/system', adminSystemRoutes);
  router.use('/api/admin/logs', adminLogRoutes);
  router.use('/api/admin/artists', adminArtistRoutes);
  router.use('/api/admin/performances', adminPerformanceRoutes);
  router.use('/api/admin/votes', adminVoteRoutes);
  router.use('/api/admin/activities', adminActivityRoutes);
  router.use('/api/admin/content', adminContentRoutes);
  router.use('/api/admin/works', adminWorkRoutes);
  router.use('/api/admin/floors', adminFloorRoutes);
  router.use('/api/admin/venues', adminVenueRoutes);

  // 兼容性路由 (保持向后兼容)
  logger.info('🔄 注册兼容性路由: /api/*');
  router.use('/api/auth', clientAuthRoutes);
  router.use('/api/users', clientUserRoutes);

  logger.info('✅ API路由配置完成');
  
  return router;
}

// 获取路由信息
export function getRouteInfo(): { client: string[], admin: string[], compatibility: string[] } {
  return {
    client: [
      '/api/client/auth/*',
      '/api/client/users/*',
      '/api/client/artists/*',
      '/api/client/performances/*',
      '/api/client/votes/*',
      '/api/client/badges/*',
      '/api/client/venues/*',
      '/api/client/floors/*',
      '/api/client/fun-facts/*',
      '/api/client/ai-assistants/*',
      '/api/client/dify-ai/*',
      '/api/client/notifications/*',
      '/api/client/navigation/*'
    ],
    admin: [
      '/api/admin/auth/*',
      '/api/admin/users/*',
      '/api/admin/roles/*',
      '/api/admin/permissions/*',
      '/api/admin/system/*',
      '/api/admin/logs/*',
      '/api/admin/artists/*',
      '/api/admin/performances/*',
      '/api/admin/votes/*',
      '/api/admin/activities/*',
      '/api/admin/content/*',
      '/api/admin/works/*',
      '/api/admin/floors/*',
      '/api/admin/venues/*'
    ],
    compatibility: [
      '/api/auth/*',
      '/api/users/*'
    ]
  };
}

export default router;